package com.efuture.chapterfive

import java.io.File

/* @Description:Kotlin语言的类型转换学习
 * @Auther: zhaoshanshan
 * @Date: 2022/03/07/12:10 下午
 */

open class Person2(val name:String){
    open fun showName()="父类的名字是${name}"
    open fun myPrintln()= println(showName())
    fun parentMethod() = println("我是父类方法")
}
class Student2(private val stuName:String):Person2(stuName){
    override fun showName(): String {
        return "子类的名字是${stuName}"
    }

    override fun myPrintln() {
       println(showName())
    }
}

fun main() {
    val p:Person2 = Student2("赵山山")
    p.myPrintln()

    // is as 关键字的使用
    println(p is Person2)//true
    println(p is Student2)//true
    println(p is File)//false

    //一般情况下 is as 配合使用
    println("===================")//false
    if(p is Person2){
        (p as Person2).parentMethod()
    }
    if(p is Student2){
        (p as Student2).myPrintln()
    }

}